﻿//////////////////////////////////////
//////add by yl 2014年8月20日14:01:31
//////主要功能:处理班组设备报修
///////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Catering_DBOpertion;

namespace Catering_Model
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public partial class BanzuDynamic
    {
        public BanzuDynamic()
        { }
        #region Model
        private int _id;
        private int _KitchenNum;
        private float _KitchenArea;
        private int _qiyouzao;
        private int _diancizao;
        private int _penlin;
        private int _miehuoqi;
        private int _miehuotan;
        private string _shebeijiankong;
        private string _gaoweishebei;
        private int _shebeishuliang;
        private int _xiyishebei;
        private int _youyanji;
        private string _lengcangku;
        private string _dongku;
        private string _ganhuoku;
        private string _zuoyerenshu;
        private string _zuoyeleixing;
        private string _zuoyezhouqi;
        private int _ClassID;
        private DateTime _savedate;
        /// <summary>
        /// 
        /// </summary>
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 日报管理编号
        /// </summary>
        public string zuoyerenshu
        {
            set { _zuoyerenshu = value; }
            get { return _zuoyerenshu; }
        }
        /// <summary>
        /// 日报管理编号
        /// </summary>
        public string zuoyeleixing
        {
            set { _zuoyeleixing = value; }
            get { return _zuoyeleixing; }
        }
        /// <summary>
        /// 日报管理编号
        /// </summary>
        public string zuoyezhouqi
        {
            set { _zuoyezhouqi = value; }
            get { return _zuoyezhouqi; }
        }
        /// <summary>
        /// 日报管理编号
        /// </summary>
        public int KitchenNum
        {
            set { _KitchenNum = value; }
            get { return _KitchenNum; }
        }
        /// <summary>
        /// 作业区编号
        /// </summary>
        public float KitchenArea
        {
            set { _KitchenArea = value; }
            get { return _KitchenArea; }
        }
        /// <summary>
        /// 班组编号
        /// </summary>
        public int qiyouzao
        {
            set { _qiyouzao = value; }
            get { return _qiyouzao; }
        }
        /// <summary>
        /// 设备名称
        /// </summary>
        public int diancizao
        {
            set { _diancizao = value; }
            get { return _diancizao; }
        }

        /// <summary>
        /// 设备型号
        /// </summary>
        public int penlin
        {
            set { _penlin = value; }
            get { return _penlin; }
        }
        /// <summary>
        /// 品牌产地
        /// </summary>
        public int miehuoqi
        {
            set { _miehuoqi = value; }
            get { return _miehuoqi; }
        }
        /// <summary>
        /// 设备故障具体描述
        /// </summary>
        public int miehuotan
        {
            set { _miehuotan = value; }
            get { return _miehuotan; }
        }
        /// <summary>
        /// 报修人
        /// </summary>
        public string shebeijiankong
        {
            set { _shebeijiankong = value; }
            get { return _shebeijiankong; }
        }
        public string gaoweishebei
        {
            set { _gaoweishebei = value; }
            get { return _gaoweishebei; }
        }
        /// <summary>
        /// 班组编号
        /// </summary>
        public int shebeishuliang
        {
            set { _shebeishuliang = value; }
            get { return _shebeishuliang; }
        }
        /// <summary>
        /// 设备名称
        /// </summary>
        public int xiyishebei
        {
            set { _xiyishebei = value; }
            get { return _xiyishebei; }
        }

        /// <summary>
        /// 设备型号
        /// </summary>
        public int youyanji
        {
            set { _youyanji = value; }
            get { return _youyanji; }
        }
        /// <summary>
        /// 品牌产地
        /// </summary>
        public string lengcangku
        {
            set { _lengcangku = value; }
            get { return _lengcangku; }
        }
        /// <summary>
        /// 设备故障具体描述
        /// </summary>
        public string dongku
        {
            set { _dongku = value; }
            get { return _dongku; }
        }
        /// <summary>
        /// 报修人
        /// </summary>
        public string ganhuoku
        {
            set { _ganhuoku = value; }
            get { return _ganhuoku; }
        }
        /// <summary>
        /// 报修人
        /// </summary>
        public int ClassID
        {
            set { _ClassID = value; }
            get { return _ClassID; }
        }
        /// <summary>
        /// 报修人
        /// </summary>
        public DateTime savedate
        {
            set { _savedate = value; }
            get { return _savedate; }
        }
        #endregion Model

        #region ExtensionMethod     
   
        /// <summary>
        /// 班组名称
        /// </summary>
        public string ClassName { get; set; }

        #endregion
    }
}
namespace Catering_Rules
{
    /// <summary>
    /// Moon
    /// </summary>
    public partial class BanzuDynamic
    {
        private readonly Catering_Operation.BanzuDynamic dal = new Catering_Operation.BanzuDynamic();
        public BanzuDynamic()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            return dal.Exists(Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.BanzuDynamic model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.BanzuDynamic model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string strwhere)
        {

            return dal.Delete(strwhere);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.BanzuDynamic GetModel(string Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        public DataSet GetList(string strWhere,string str)
        {
            return dal.GetList(strWhere,"");
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.BanzuDynamic> GetModelList(string strWhere )
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.BanzuDynamic> DataTableToList(DataTable dt)
        {
            List<Catering_Model.BanzuDynamic> modelList = new List<Catering_Model.BanzuDynamic>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Catering_Model.BanzuDynamic model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
namespace Catering_Operation
{
    /// <summary>
    /// 数据访问类:Moon
    /// </summary>
    public partial class BanzuDynamic
    {
        public BanzuDynamic()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Moon");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.BanzuDynamic model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into BanZuDynamic(");
            strSql.Append("KitchenNum,KitchenArea,qiyouzao,diancizao,penlin,miehuoqi,miehuotan,shebeijiankong,gaoweishebei,shebeishuliang,xiyishebei,youyanji,lengcangku,dongku,ganhuoku,zuoyerenshu,zuoyeleixing,zuoyezhouqi,ClassID,savedate)");
            strSql.Append(" values (");
            strSql.Append("@KitchenNum,@KitchenArea,@qiyouzao,@diancizao,@penlin,@miehuoqi,@miehuotan,@shebeijiankong,@gaoweishebei,@shebeishuliang,@xiyishebei,@youyanji,@lengcangku,@dongku,@ganhuoku,@zuoyerenshu,@zuoyeleixing,@zuoyezhouqi,@ClassID,@savedate)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@KitchenNum", SqlDbType.Int,-1),
                    new SqlParameter("@KitchenArea", SqlDbType.Float,-1),
                    new SqlParameter("@qiyouzao", SqlDbType.Int,-1),
					new SqlParameter("@diancizao", SqlDbType.Int,-1),
					new SqlParameter("@penlin", SqlDbType.Int,-1),
					new SqlParameter("@miehuoqi", SqlDbType.Int,-1),
                    new SqlParameter("@miehuotan", SqlDbType.Int,-1),
                    new SqlParameter("@shebeijiankong", SqlDbType.VarChar,50),
                    new SqlParameter("@gaoweishebei", SqlDbType.VarChar,50),
                    new SqlParameter("@shebeishuliang", SqlDbType.Int,-1),
					new SqlParameter("@xiyishebei", SqlDbType.Int,-1),
					new SqlParameter("@youyanji", SqlDbType.Int,-1),
					new SqlParameter("@lengcangku", SqlDbType.VarChar,50),
                    new SqlParameter("@dongku", SqlDbType.VarChar,50),
                    new SqlParameter("@ganhuoku", SqlDbType.VarChar,50),
                    new SqlParameter("@zuoyerenshu", SqlDbType.VarChar,50),
                    new SqlParameter("@zuoyeleixing", SqlDbType.VarChar,50),
                    new SqlParameter("@zuoyezhouqi", SqlDbType.VarChar,50),
                    new SqlParameter("@ClassID", SqlDbType.VarChar,50),
					new SqlParameter("@savedate", SqlDbType.Date,-1)};
            parameters[0].Value = model.KitchenNum;
            parameters[1].Value = model.KitchenArea;
            parameters[2].Value = model.qiyouzao;
            parameters[3].Value = model.diancizao;
            parameters[4].Value = model.penlin;
            parameters[5].Value = model.miehuoqi;
            parameters[6].Value = model.miehuotan;
            parameters[7].Value = model.shebeijiankong;
            parameters[8].Value = model.gaoweishebei;
            parameters[9].Value = model.shebeishuliang;
            parameters[10].Value = model.xiyishebei;
            parameters[11].Value = model.youyanji;
            parameters[12].Value = model.lengcangku;
            parameters[13].Value = model.dongku;
            parameters[14].Value = model.ganhuoku;
            parameters[15].Value = model.zuoyerenshu;
            parameters[16].Value = model.zuoyeleixing;
            parameters[17].Value = model.zuoyezhouqi;
            parameters[18].Value = model.ClassID;
            parameters[19].Value = model.savedate;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.BanzuDynamic model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update DailyReportInfo set ");
            strSql.Append("EquipCName=@EquipCName,");
            strSql.Append("EquipModel=@EquipModel,");
            strSql.Append("BrandArea=@BrandArea,");
            strSql.Append("ConDesc=@ConDesc,");
            strSql.Append("UserCName=@UserCName");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@EquipCName", SqlDbType.VarChar,50),
                    new SqlParameter("@EquipModel", SqlDbType.VarChar,50),                    
                    new SqlParameter("@BrandArea", SqlDbType.VarChar,500),
                    new SqlParameter("@ConDesc", SqlDbType.Text,-1),
                    new SqlParameter("@UserCName", SqlDbType.VarChar,50),
                    new SqlParameter("@Id", SqlDbType.Int,4)};
            //parameters[0].Value = model.EquipCName;
            //parameters[1].Value = model.EquipModel;
            //parameters[2].Value = model.BrandArea;
            //parameters[3].Value = model.ConDesc;
            //parameters[4].Value = model.UserCName;
            //parameters[5].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string strWhere)
        {
            string sql = "delete from BanzuDynamic where " + strWhere;
            int rows = DbHelperSQL.ExecuteSql(sql);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Moon ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.BanzuDynamic GetModel(string Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ClassId from Contractor");
            strSql.Append(" where CName=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.VarChar,50)
			};
            parameters[0].Value = Id;

            Catering_Model.BanzuDynamic model = new Catering_Model.BanzuDynamic();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.BanzuDynamic DataRowToModel(DataRow row)
        {
            Catering_Model.BanzuDynamic model = new Catering_Model.BanzuDynamic();
            if (row != null)
            {
                if (row["id"].ToString() != "")
                {
                    model.Id = int.Parse(row["id"].ToString());
                }
                if (row["KitchenNum"].ToString() != "")
                {
                    model.KitchenNum = int.Parse(row["KitchenNum"].ToString());
                }
                if (row["KitchenArea"].ToString() != "")
                {
                    model.KitchenArea = float.Parse(row["KitchenArea"].ToString());
                }
                if (row["qiyouzao"].ToString() != "")
                {
                    model.qiyouzao = int.Parse(row["qiyouzao"].ToString());
                }
                if (row["diancizao"].ToString() != "")
                {
                    model.diancizao = int.Parse(row["diancizao"].ToString());
                }
                if (row["penlin"].ToString() != "")
                {
                    model.penlin = int.Parse(row["penlin"].ToString());
                }
                if (row["miehuoqi"].ToString() != "")
                {
                    model.miehuoqi = int.Parse(row["miehuoqi"].ToString());
                }
                if (row["miehuotan"].ToString() != "")
                {
                    model.miehuotan = int.Parse(row["miehuotan"].ToString());
                }
                model.shebeijiankong = row["shebeijiankong"].ToString();
                model.gaoweishebei = row["gaoweishebei"].ToString();
                if (row["shebeishuliang"].ToString() != "")
                {
                    model.shebeishuliang = int.Parse(row["shebeishuliang"].ToString());
                }
                if (row["xiyishebei"].ToString() != "")
                {
                    model.xiyishebei = int.Parse(row["xiyishebei"].ToString());
                }
                if (row["youyanji"].ToString() != "")
                {
                    model.youyanji = int.Parse(row["youyanji"].ToString());
                }
                model.lengcangku = row["lengcangku"].ToString();
                model.dongku = row["dongku"].ToString();
                model.ganhuoku = row["ganhuoku"].ToString();
                if (row["savedate"].ToString() != "")
                {
                    model.savedate = DateTime.Parse(row["savedate"].ToString());
                }
                if (row["ClassID"].ToString() != "")
                {
                    model.ClassID = int.Parse(row["ClassID"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 *");
            strSql.Append(" FROM BanzuDynamic ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere + " order by id desc");
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetList(string strWhere, string str)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *");
            strSql.Append(" FROM BanzuDynamic ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" Id,MoonName,ClassId,Remark ");
            strSql.Append(" FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.Id desc");
            }
            strSql.Append(")AS Row, T.*  from Moon T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Moon";
            parameters[1].Value = "Id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}